/*
 * Created Date: Friday November 23rd 2018 10:37:22 am
 * Author: xionghaizi
 * -----
 * Last Modified:Friday November 23rd 2018 10:37:22 am
 * Modified By: xionghaizi
 * -----
 * Copyright (c) 2018 <<company>>
 */
(function ($) {
  $.fn.table = function (option) {
    var d = this.selector; // 获取当前id或者class。
    var u = $(d).attr("id") || $(d).attr("class"); // 这个dom是否真实存在。
    if (!u) 
      return false;

    if (option.columns && !(option.columns.length > 0))
      return false;
    var th = ""
    $.each(option.columns, function(i, v) {
      // console.log(i, v);
      if (v.className) {
        th +="<th class='+v.className+'>"+v.title+"</th>";
      } else {
        th += "<th>" + v.title + "</th>";
      }
    })
    var divClassName = option.responsive ? 'table-responsive' : ''; // 是否自适应
    var tableClassName = (option.type && option.type.length > 0) ? "table" +" "+ option.type : "table";
    var dom = "<div class='" + divClassName+"'>" +
                  "<table class='"+ tableClassName+"'>"+
                  "<thead>"+
                  "<tr>"+
                  th+
                  "</tr>"+
                  "</thead>"+
                  "<tbody>"+
                  "</tbody>"+
                  "</table>"+
              "</div>";
    $(d).append(dom);
  }
  $.fn.tr = function (data) {
    
  }
})(jQuery);

// var type = ""
var option = {
  columns: [
    {
      title: "姓名",
      dataIndex: "name"
    }, {
      title: "性别",
      dataIndex: "sex",
      render: function (data) {
        return  data
      }
    }
  ],
  responsive: false,
  type: "table-bordered table-hover"
}
$("#test").table(option)
